﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Activities;
using MTechApplicationServices.Contracts;
using MTechApplicationServices.Data;

namespace MTechApplicationServices.Activities
{

    public sealed class UpdateSelectionApproved : CodeActivity
    {
        public InArgument<bool> SelectionApproved { get; set; }
        public InArgument<int> ApplicantID { get; set; }
        
        protected override void Execute(CodeActivityContext context)
        {
            using (MTechApplicationDataEntities ctx = new MTechApplicationDataEntities())
            {
                bool result = SelectionApproved.Get(context);
                int appID = ApplicantID.Get(context);

                var query = from a in ctx.Applicants
                            where a.ApplicationID == appID
                            select a;

                Applicant applicant = query.FirstOrDefault();
                applicant.SelectionApproved = result;

                ctx.SaveChanges();
            }
        }
    }
}
